package com.ljx.QueueStack;

import java.util.Stack;

/**
 * @author 李加喜
 * @Package com.ljx.QueueStack
 * @date 2021-11-30 15:41
 * 使用栈来实现队列
 */
class MyQueue {

    private Stack<Integer> s1,s2;

    public MyQueue() {
        s1=new Stack<>();
        s2=new Stack<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        peek();
        return s2.pop();
    }

    public int peek() {
        if (s2.isEmpty()){
            while (!s1.isEmpty()){
                Integer pop = s1.pop();
                s2.push(pop);
            }
        }
        // peek不会删除栈的数据  但是pop会删除栈里面的数据
        return s2.peek();
    }

    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */
